<template>
	<view class="container">
		<button @click="toPay()">去下单</button>
	</view>
</template>

<script setup>
	import { apiPayPrepare } from '@/utils/api.js';
	const toPay = async () => {
		const param = {
			'id': 'plan002'
		}
		const {success, message, data} = await apiPayPrepare(param);
		if (success) {
			uni.requestPayment({
				provider: 'wxpay',
				timeStamp: data.timestamp,
				nonceStr: data.nonceStr,
				package: data.packageStr,
				signType: data.signType,
				paySign: data.paySign,
				complete: (result) => {
					uni.hideLoading();
				}
			})
		} else {
			uni.showToast({
				title: message,
				icon: 'none'
			})
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 24rpx;
	}
</style>
